//2. Descriptive Statistics  - Land Titles Vs Attacks by Region

loc dir "/Users/mateo/Desktop/"
	
	cd "/Users/mateo/Desktop/"
	
		use "/Users/mateo/Desktop/master_violence_landtitle_caracteristicas.dta", clear
		
		
		gen Region=""
		replace Region="Andean" if gandina==1
		replace Region="Caribbean" if gcaribe==1
		replace Region="Pacific" if gpacifica==1
		replace Region="Orinoquía" if gorinoquia==1
		replace Region="Amazon" if gamazonia==1
		
		label define title 0 "Control" 1 "Treatment"
		label values any_title title
		
		*  Land Titles (>1995)
		preserve
		
			egen all_violence=rowtotal(sumattacks_public sumattacks_guerrilla sumattacks_paramilitary)

				
			collapse (sum) total_land_title all_violence if Año>1994 & Año<2012, by(Año)
			
			sort Año
			replace total_land_title=. if total_land_title==0
			
			
			twoway bar total_land_title Año, bstyle(1) bfcolor(black) fcolor(black)  xvarlab("") ytitle("# Land Titles (1996 - 2012)")  yaxis(1) || scatter  total_land_title Año, msym(none) mlab(total_land_title) mlabpos(12)  mlabcolor(black) ||connected all_violence  Año, yaxis(2) ytitle("# Attacks (Police, Army, Guerrilla & Paramilitary)", axis(2)) graphregion(fcolor(white))  mcolor(blue) msymbol(oh) lcolor(blue) lpattern(dash) lwidth(medthick) name("total_title_violence", replace)  /*note(" " "Note: Slave Ratio = # Slaves/Total Population (1843)", size(small))*/ legend(order(1 "# Titles"   3 "# Attacks"))
			
			
			graph bar  total_land_title,  over(Año, label(angle(45) labsize(3)) )  nofill ytitle("# Land Titles (1996 - 2012)") /// 
				bar(1,  fcolor(black)) b1title(Year) blabel(bar, format(%4.0f) size(3))  graphregion(color(white)) name("total_title_bar", replace) nodraw
				
				*graph export `"`dir'\LaTex\total_title.png"', replace
				
		restore
		
		preserve
							
			collapse (sum) total_land_title pct_minority85  (mean) share_afpop05 slave_ratio_norm, by(Region)
					
			*replace total_land_title=. if total_land_title==0
					
				encode Region, gen(region)
				
				lab var region "Region"
				lab var Region ""
				lab var slave_ratio "Slave Ratio"
				lab var total_land_title "Land Titles"
				lab var pct_minority85 "% African-descent'05"

				twoway bar total_land_title region, /*bstyle(none)*/ bfcolor(black)  xvarlab("") ytitle("# Land Titles (1996 - 2012)")  yaxis(1) || connected slave_ratio_norm  region, yaxis(2) ytitle("Mean Normalized Slave Ratio (1843)", axis(2)) graphregion(fcolor(white)) xlabel(1 "Amazon" 2 "Andean" 3 "Caribbean" 4 "  Orinoquía" 5 "Pacific", tlength(0) grid gmin gmax labsize(small)) mcolor(red) msymbol(oh) lcolor(red) lpattern(dash) lwidth(medthick) name("total_title_Region", replace) nodraw  /*note(" " "Note: Slave Ratio = # Slaves/Total Population (1843)", size(small))*/ 

				*graph bar total_land_title , graphregion(fcolor(white)) over(Region, label(angle(45) labsize(3)) )  nofill  ytitle("# Land Titles (1996 - 2012)") bar(1,  fcolor(black)) b1title(Region)    
				
				twoway bar total_land_title region, bstyle(none) bfcolor(black)  xvarlab("") ytitle("# Land Titles (1996 - 2012)")  yaxis(1) || connected share_afpop05  region, yaxis(2) ytitle("% African-descent (2005)", axis(2)) graphregion(fcolor(white)) xlabel(1 "Amazon" 2 "Andean" 3 "Caribbean" 4 "  Orinoquía" 5 "Pacific", tlength(0) grid gmin gmax labsize(small)) mcolor(red) msymbol(oh) lcolor(red) lpattern(dash) lwidth(medthick) name("Af_descent_Region", replace)  /*note(" " "Note: Slave Ratio = # Slaves/Total Population (1843)", size(small))*/ legend(off) nodraw
				
				
				graph bar total_land_title share_afpop05, graphregion(fcolor(white)) over(Region, label(angle(0) labsize(3)) )  nofill  ytitle("") bar(1,  fcolor(black)) /*b1title(Region)*/  legend(order(1 "# Titles" 2 "% African-descent '05")) blabel(bar, format(%4.0f)) nodraw  name("Af_descent_bar", replace) 

				*graph export `"`dir'\LaTex\total_title.png"', replace
				 
		restore
		
		graph combine  Af_descent_bar total_title_violence, ///
		saving(`"/Users/mateo/Desktop/land_titles.png"', replace)	  cols(2) title("")  graphregion(color(white)) altshrink 
		
		graph export `"/Users/mateo/Desktop/land_titles.png"', replace






